home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Hráč 2004 August
/
Hrac_72_2004-08_dvd.iso
/
dema
/
Rapid Gun
/
rg_setup.exe
/
common
/
image_SobelFilter.fx
< prev
next >
Wrap
Text File
|
2004-04-19
|
2KB
|
66 lines
// LF2 Engine
// (C) 2002-3 7FX
//---------------------------------------------------------------------------
// Desc
string desc : Description = "Image shader - Sobel edge detector.";
// Shader type phase
string type : Type = "image";
//---------------------------------------------------------------------------
// Constants
const float4 cLum = {0.3f, 0.59f, 0.11f, 1.f};
const float2 sampleOffsets[8] : SampleOffsets;
// Render target texture
texture RT : RenderTargetFSMap;
//---------------------------------------------------------------------------
sampler sRT = sampler_state
{
Texture = <RT>;
MinFilter = POINT;
MagFilter = POINT;
AddressU = CLAMP;
AddressV = CLAMP;
};
//---------------------------------------------------------------------------
// Pixel shader
float4 PS(float2 uv: TEXCOORD0) : COLOR
{
int i =0;
float4 c = .5;
float2 texCoords;
float4 texSamples[8];
float4 vertGradient;
float4 horzGradient;
for(i =0; i < 8; i++)
{
texCoords = uv + sampleOffsets[i]; // add sample offsets
// take sample
texSamples[i] = tex2D(sRT, texCoords);
// convert to b&w
texSamples[i] = dot(texSamples[i].rgb, 0.333333f/*cLum.rgb*/);
}
// VERTICAL Gradient
vertGradient = -(texSamples[0] + texSamples[5] + 2*texSamples[3]);
vertGradient += (texSamples[2] + texSamples[7] + 2*texSamples[4]);
// Horizontal Gradient
horzGradient = -(texSamples[0] + texSamples[2] + 2*texSamples[1]);
horzGradient += (texSamples[5] + texSamples[7] + 2*texSamples[6]);
// not optimized!
c = sqrt(horzGradient*horzGradient + vertGradient*vertGradient);
return c;
}
//---------------------------------------------------------------------------
technique vs0_ps20
{
pass p0
{
ZEnable = false;
ZWriteEnable = false;
PixelShader = compile ps_2_0 PS();
}
}
//---------------------------------------------------------------------------